Fix detached worktree name handling#15
Merged
Merged
Conversation
Previously, all detached worktrees showed as "(Detached)" in lists, making them indistinguishable. Also, couldn't switch to detached worktrees by the name given during creation. Changes: - Store user-given names in per-worktree git config using worktreeConfig extension - Enable extensions.worktreeConfig to support per-worktree config - Retrieve stored names when listing worktrees, fallback to (detached-<commit>) - Fix base branch selection: detached worktrees now use HEAD instead of default_base - Add comprehensive tests for detached worktree operations Implementation: - Added enable_worktree_config(), set_worktree_name(), get_worktree_name() in git.py - Modified create_worktree() to store names for detached worktrees - Modified list_worktrees() to retrieve stored names - find_worktree_by_name() now works for detached worktrees This fix makes detached worktrees fully functional for list/switch/run/delete commands.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical usability issue where all detached worktrees were indistinguishable in listings and couldn't be referenced by their user-given names. The solution stores user-provided names in per-worktree git config using the worktreeConfig extension.
Changes:
- Store and retrieve user-given names for detached worktrees using per-worktree git config
- Fix base branch selection logic for detached worktrees to use HEAD instead of default_base
- Add comprehensive test coverage for all detached worktree operations (create, list, switch, run, delete)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tools/wt-worktree/wt/git.py | Added three new functions to enable worktree config extension and manage per-worktree name storage |
| tools/wt-worktree/wt/worktree.py | Modified list_worktrees() to retrieve stored names, updated create_worktree() to store names and fix base branch logic, updated comment in find_worktree_by_name() |
| tools/wt-worktree/tests/test_cli.py | Added 6 comprehensive integration tests covering all detached worktree operations |
| tools/wt-worktree/notes.md | Documented the problem, solution, implementation details, and lessons learned |
| tools/wt-worktree/README.md | Added documentation and examples for detached worktree usage |
| Agents.md | Added workflow tips and testing guidelines for development |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Detached worktrees created before this fix (or via raw git commands)
don't have stored names in config. Added path-based inference to handle
these cases.
Changes:
- Added _infer_name_from_path() method to infer names from worktree paths
- Fallback chain: stored config → inferred from path → (detached-<commit>)
- Works with common path patterns like ../{repo}-{name} and ../{name}
- Added test for backward compatibility scenario
This ensures switch/list/run commands work even for legacy detached worktrees.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, all detached worktrees showed as "(Detached)" in lists, making
them indistinguishable. Also, couldn't switch to detached worktrees by the
name given during creation.
Changes:
Implementation:
This fix makes detached worktrees fully functional for list/switch/run/delete commands.